#include <Windows.h>
#include <sphelper.h>
#pragma warning(disable:4995)
#include <iostream>
#include "Speaker.h"
#include "Grammar.h"
#include "CommandHandler.h"
#include <functiondiscoverykeys.h>
#include <MMDeviceAPI.h>
#include <AudioClient.h>
#include <AudioPolicy.h>
#include "Globals.h"

#ifndef VOICE_RECOGNIZER_H
#define VOICE_RECOGNIZER_H
class VoiceRecognizer{
private:
	LPWSTR pwszText; //Received text
	HANDLE hEvent; //Recognizing done
	HRESULT hr;
	CSpEvent evt;
	SPPHRASE *pParts; //Phrase parts of the phrase that was understood
	ISpPhrase *pPhrase;// The whole phrase that was understood
	ULONGLONG ullEvents; //Events mask
	CComPtr<ISpRecognizer> cpEngine; //Speech recognition engine
	CComPtr<ISpRecoContext> cpRecoCtx; //Context
	CComPtr<ISpRecoGrammar> cpGram; //The grammar to understand
	CComPtr<ISpStream> cpInputStream; //The microphone channel that is being listened to
	Speaker* speaker; //Reference to the speaker class
	CommandHandler *commandHandler; //Reference to the actuator
	LPWSTR text; //Recognized text
	bool confirmPhrase; //Used for confirming actions
	bool done; //To stop listening
	void run(); //Start listening
	void recognized(ISpPhrase *phrase);
	void notRecognized(void);
	void confPhrase(bool conf);
	Grammar *gr;

public:
	VoiceRecognizer(CommandHandler *commandHandler);
	~VoiceRecognizer();
	void listen(bool listen); //Whether or not the recognizer is actively listening
	void confirm(const wchar_t * textToConfirm);
	void doReset(void);
	void doStop(void);


};
#endif